package br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin;

import com.gwtext.client.widgets.layout.ColumnLayoutData;
import com.gwtext.client.widgets.portal.Portal;
import com.gwtext.client.widgets.portal.PortalColumn;
import com.gwtext.client.widgets.portal.Portlet;

/**
 * @author Renato Miceli
 */
public class DefaultPortal extends Portal {

	private static class GenericPortalColumn extends PortalColumn {

		public GenericPortalColumn() {
			this.setPaddings(10, 10, 0, 10);
		}

	}

	private int columnCounter;

	private PortalColumn[] columns;

	public DefaultPortal() {

		this.init();
	}

	public void addPortlet(Portlet portlet) {
		this.columns[columnCounter].add(portlet);
		columnCounter = (columnCounter + 1) % this.columns.length;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void clear() {
		super.clear();
		this.init();
		this.doLayout();
	}
	
	private void init() {
		this.columnCounter = 0;
		this.columns = new PortalColumn[] { new GenericPortalColumn(), new GenericPortalColumn(), new GenericPortalColumn() };
		for (PortalColumn column : columns) {
			this.add(column, new ColumnLayoutData(.33));
		}
	}

}
